<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>mock.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">mock.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    Provides a mocking framework in Closure to make unit tests easy
 to write and understand. The methods provided here can be used to replace
 implementations of existing objects with 'mock' objects to abstract out
 external services and dependencies thereby isolating the code under test.
 Apart from mocking, methods are also provided to just monitor calls to an
 object (spying) and returning specific values for some or all the inputs to
 methods (stubbing).

 Design doc : <a href="http://go/closuremock">http://go/closuremock</a>
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="closure_goog_labs_mock_mock.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/closure/goog/labs/mock/mock.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">labs/mock/mock.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_MethodBinding_.html">
          goog.labs.mock.MethodBinding_</a><br/>
        <div class="class-details">Represents a binding between a method name, args and a stub.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_MockFunctionManager_.html">
          goog.labs.mock.MockFunctionManager_</a><br/>
        <div class="class-details">Sets up mock for the given function, stubbing out. By default, all stubs
return <code>undefined</code>, though stubs can be later defined using
<code>goog.labs.mock.when</code>.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_MockManager_.html">
          goog.labs.mock.MockManager_</a><br/>
        <div class="class-details">Base class that provides basic functionality for creating, adding and
finding bindings, offering an executor method that is called when a call to
the stub is made, an array to hold the bindings and the mocked item, among
other things.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_MockObjectManager_.html">
          goog.labs.mock.MockObjectManager_</a><br/>
        <div class="class-details">Sets up mock for the given object (or class), stubbing out all the defined
methods. By default, all stubs return <code>undefined</code>, though stubs can be
later defined using <code>goog.labs.mock.when</code>.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_MockSpyManager_.html">
          goog.labs.mock.MockSpyManager_</a><br/>
        <div class="class-details">Sets up the spying behavior for the given object.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_StubBinder_.html">
          goog.labs.mock.StubBinder_</a><br/>
        <div class="class-details">The stub binder is the object that helps define the stubs by binding
method name to the stub method.</div>
 </div>
 <div class="fn-constructor">
        <a href="class_goog_labs_mock_VerificationError.html">
          goog.labs.mock.VerificationError</a><br/>
        <div class="class-details">Error thrown when verification failed.</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock.MockManager_.call"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.MockManager_.</span><span class="entryName">call<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line137">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock.MockObjectManager_.call"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.MockObjectManager_.</span><span class="entryName">call<span class="args">()</span>
        </span>
      </div>


     <div class="entryOverview">
       <span class='nodesc'>No description.</span>
     </div>

   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line320">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.</span><span class="entryName">mock<span class="args">(<span class="arg">objectOrClass</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
      </div>


     <div class="entryOverview">
       Mocks a given object or class.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">objectOrClass</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
        <div class="entryOverview">An instance or a constructor of a class to be mocked.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>&nbsp;
            The mocked object.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line43">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mockFunction"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.</span><span class="entryName">mockFunction<span class="args">(<span class="arg">func</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>
      </div>


     <div class="entryOverview">
       Mocks a given function.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">func</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>
        <div class="entryOverview">A function to be mocked.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function">Function</a></span></div>&nbsp;
            The mocked function.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line59">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock.spy"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.</span><span class="entryName">spy<span class="args">(<span class="arg">obj</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
      </div>


     <div class="entryOverview">
       Spies on a given object.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">obj</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
        <div class="entryOverview">The object to be spied on.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>&nbsp;
            The spy object.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line73">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock.verify"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.</span><span class="entryName">verify<span class="args">(<span class="arg">obj</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
      </div>


     <div class="entryOverview">
       Returns an object that can be used to verify calls to specific methods of a
given mock.
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">obj</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
        <div class="entryOverview">The mocked object.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>&nbsp;
            The verifier.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line90">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.labs.mock.when"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.</span><span class="entryName">when<span class="args">(<span class="arg">mockObject</span>)</span>
        </span>
        &#8658; <div class="fullType"><span class="type"><a href="class_goog_labs_mock_StubBinder_.html">goog.labs.mock.StubBinder_</a></span></div>
      </div>


     <div class="entryOverview">
       Facilitates (and is the first step in) setting up stubs. Obtains an object
on which, the method to be mocked is called to create a stub. Sample usage:

var mockObj = goog.labs.mock(objectBeingMocked);
goog.labs.mock.when(mockObj).getFoo(3).thenReturn(4);
     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">mockObject</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a></span></div>
        <div class="entryOverview">The mocked object.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<div class="fullType"><span class="type"><a href="class_goog_labs_mock_StubBinder_.html">goog.labs.mock.StubBinder_</a></span></div>&nbsp;
            The property binder.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line528">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



  <h2>Global Properties</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>





  <a name="goog.labs.mock.PROTOTYPE_FIELDS_"></a>

  <td>


     <div class="arg">
        <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.labs.mock.</span><span class="entryName">PROTOTYPE_FIELDS_</span>
        : <div class="fullType"><span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></span>.&lt;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>&gt;</div>
     </div>


     <div class="entryOverview">
       This array contains the name of the functions that are part of the base
Object prototype.
Basically a copy of goog.object.PROTOTYPE_FIELDS_.
     </div>

  </td>


  <td class="view-code">
     <a href="closure_goog_labs_mock_mock.js.source.html#line116">Code &raquo;</a>
  </td>
     </tr>


  </table>
</div>



      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory mock</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="labs/mock/mock.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
